package com.veryGood.common.result;

import com.veryGood.common.util.Constants;

/**
 * @param <T> 返回数据的类型
 */
public class Res<T> {
    private Integer code;
    private String msg;
    private Integer count;
    private T data;

    public static <T> Res<T> success() {
        return new Res<>(Constants.ok, Constants.message_OK, null, null);
    }

    public static <T> Res<T> success(T data) {
        return new Res<>(Constants.ok, Constants.message_OK, null, data);
    }

    public static <T> Res<T> success(String msg, T data) {
        return new Res<>(Constants.ok, msg, null, data);
    }

    public static <T> Res<T> success(String msg, Integer count, T data) {
        return new Res<>(Constants.ok, msg, count, data);
    }

    public static <T> Res<T> error() {
        return new Res<>(Constants.error, Constants.message_ERROR, null, null);
    }

    public static <T> Res<T> error(String msg) {
        return new Res<>(Constants.error, msg, null, null);
    }

    public static <T> Res<T> error(String msg, T data) {
        return new Res<>(Constants.error, msg, null, data);
    }

    public static <T> Res<T> error(String msg, Integer count, T data) {
        return new Res<>(Constants.error, msg, count, data);
    }

    public Res() {
    }

    public Res(Integer code, String msg, Integer count, T data) {
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}